#
# This file is part of NetEmbryo
#
# Copyright (C) 2008 by LScube team <team@streaming.polito.it>
# See AUTHORS for more details
#
# NetEmbryo is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# NetEmbryo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with NetEmbryo; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#

BEGIN {
    print "/* Generated by genmain.awk */\n",
	"#include <glib.h>\n",
	"\n",
	"int main(int argc, char *argv[])\n",
	"{\n",
	"    if (!g_thread_supported ()) g_thread_init (NULL);\n",
	"    g_test_init(&argc, &argv, NULL);\n";
}

{
    suitename = $2;
    subsuitename = $2;
    sub("^.*tests/", "", suitename);
    sub("[_a-z0-9-]+\\.c$", "", suitename);

    sub("^.*tests/", "", subsuitename);
    sub("/?[_a-z0-9-]+/", "", subsuitename);
    sub("\\.c$", "", subsuitename);
    sub("^//", "/", subsuitename);

    testname = $1;
    sub("test_", "", testname);
    subsuite_re = "^" subsuitename "_";
    sub(subsuite_re, "", testname);

    printf "{ extern void %s();\n", $1;
    printf "  g_test_add_func(\"/%s/%s/%s\", %s); }\n",
	suitename, subsuitename, testname, $1;
}

END {
    print "\n",
	"   return g_test_run();\n",
	"}\n";
}
